/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.sprite.display;
import flash.display.BitmapData;
import hapi.sprite.sheet.CopyPixelsSpriteSheet;

class CopyPixelsSpriteSheetDisplay extends BitmapSpriteSheetDisplay {

	var spriteSheet:CopyPixelsSpriteSheet;
	
	public function new(spriteSheet:CopyPixelsSpriteSheet, ?x:Float = 0.0, ?y:Float = 0.0) {
		super(new BitmapData(spriteSheet.width, spriteSheet.height), spriteSheet.totalFrames, x, y);
		this.spriteSheet = spriteSheet;
		goto(1);
	}
	
	inline function render() {
		if(isVisible()) {
			#if cpp
				bitmapData.clear(0);
			#end
			spriteSheet.drawSpriteOn(this, currentFrame, dest);
		}
	}
	
	public override function goto(frame:Int) {
		if(frame <= totalFrames && frame >= 1 && this.currentFrame != frame) {
			this.currentFrame = frame;
			render();
		}
	}
}